package inputFrames;

import java.awt.Graphics;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;

import constants.Constants;

import person.PersonInfo;

public class PersonInfoInputPanel extends JPanel {
	private JLabel heightLabel_front, heightLabel_back;
	private JLabel weightLabel_front, weightLabel_back;
	private JSpinner heightSpinner;
	private JSpinner weightSpinner;

	public PersonInfoInputPanel() {
		this.setLayout(null);
		this.setBackground(Constants.PANEL_BACKGROUND_COLOR);
		this.setSize(Constants.INPUT_PANEL_SIZE_WIDTH, Constants.INPUT_PANEL_SIZE_HEIGHT);

		// height components
		heightLabel_front = new JLabel("Height :");
		heightLabel_front.setHorizontalAlignment(SwingConstants.RIGHT);
		heightLabel_front.setBounds(50, 100, 50, 50);
		this.add(heightLabel_front);

		heightSpinner = new JSpinner();
		heightSpinner.setModel(new SpinnerNumberModel(160, 100, 220, 1));
		heightSpinner.setBounds(120, 112, 50, 25);
		this.add(heightSpinner);
		
		heightLabel_back = new JLabel(" cm");
		heightLabel_back.setHorizontalAlignment(SwingConstants.RIGHT);
		heightLabel_back.setBounds(140, 100, 50, 50);
		this.add(heightLabel_back);

		// weight componenets
		weightLabel_front = new JLabel("Weight :");
		weightLabel_front.setHorizontalAlignment(SwingConstants.RIGHT);
		weightLabel_front.setBounds(50, 150, 50, 50);
		this.add(weightLabel_front);

		weightSpinner = new JSpinner();
		weightSpinner.setModel(new SpinnerNumberModel(60, 20, 200, 1));
		weightSpinner.setBounds(120, 162, 50, 25);
		this.add(weightSpinner);
		
		weightLabel_back = new JLabel(" kg");
		weightLabel_back.setHorizontalAlignment(SwingConstants.RIGHT);
		weightLabel_back.setBounds(140, 150, 50, 50);
		this.add(weightLabel_back);

	}
	
	public void paint(Graphics g) {
        // TODO Auto-generated method stub
        super.paint(g);
        
        g.drawImage(Constants.INPUT_IMG, 3, 15, this);
    }

	public void inputInfo(PersonInfo personInfo) {
		personInfo.setWeight((int) weightSpinner.getValue());
		personInfo.setHeight((int) heightSpinner.getValue());

		personInfo.setBMI();
	}
}
